#!/usr/bin/python
# -*- coding: UTF-8 -*-

# subversion info:
# $HeadURL: $
# $Author: $
# $Id: $
# $Revision: $

from distutils.core import setup
import os
import setuptools
import conf
import subprocess


class Sphinx(setuptools.Command):

  description = 'Sphinx documentation'
  user_options = []
  doc_src = 'HtpcUtils'

  def initialize_options(self):
    pass

  def finalize_options(self):
    pass

  def run(self):
    print 'Generating Sphinx documentation'

    # Static directory
    for path in conf.html_static_path:
      if not os.access(path, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
        os.mkdir(path)

    # Templates directory
    for path in conf.templates_path:
      if not os.access(path, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
        os.mkdir(path)

    assert subprocess.call(['make', 'clean']) == 0
    assert subprocess.call(['make', 'html']) == 0

dataDir = '/usr/share/htpc-utils'
setup (
    cmdclass={'sphinx': Sphinx},
    name='HtpcUtils',
    version='0.2',
    description='',
    author='Rafael Treviño Menéndez',
    author_email='skasi.7@gmail.com',
    platforms='UNIX',
    data_files=[
      ('/etc',
        ['htpc-utils.yml']
      ),
      (dataDir + '/scripts',
        ['scripts/subdownloader.sh',
          'scripts/sub-daemon.sh']
      ),
      (dataDir + '/confs',
        ['confs/core.conf',
          'confs/execute.conf',
          'confs/config.yml']
      )
    ],
    packages=['HtpcUtils'],
    scripts=['sub-daemon', 'htpc-event']
)

